package com.neusoft.news.controller.clue;

import com.neusoft.news.bean.Clue;
import com.neusoft.news.controller.BaseServlet;
import com.neusoft.news.dao.ClueDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 线索新增
 *
 * @author wh
 * @ClassName: ClueAddServlet
 * @Description: 线索新增
 * @date 2021年5月23日
 * @since JDK 1.8
 */
@WebServlet("/clueAdd")
public class ClueAddServlet extends BaseServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
        resp.setContentType("text/html;charset=utf-8");
        String clueTime = req.getParameter("clue_time");
        String clueContent = req.getParameter("clue_content");
        String clueReporter = req.getParameter("clue_reporter");

        Clue clue = new Clue();
        clue.setClueContent(clueTime + "\n" + clueContent);
        clue.setClueReporter(clueReporter);

        ClueDao clueDao = new ClueDao();
        int i = clueDao.addClue(clue);

        resp.sendRedirect("/clueList");
//        req.getRequestDispatcher("/clueList")
//                .forward(req, resp);
    }
}
